package com.yunweiweishi.xuhuanpaltform.yuhuan_app.controller;


import com.yunweiweishi.xuhuanpaltform.yuhuan_app.comm.conf.CommonResult;
import com.yunweiweishi.xuhuanpaltform.yuhuan_app.pojo.Equipment;
import com.yunweiweishi.xuhuanpaltform.yuhuan_app.service.EquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "设备", tags = {"设备controller"})
@RestController
@RequestMapping("equipment")
public class EquipmentController {


    /**
     * 全局的定义类
     */
    @Autowired
    private CommonResult result;


    @Autowired
    private EquipmentService equipmentService;

    @ApiOperation( value = "查询设备")
    @GetMapping("/findList")
    public CommonResult FindAll() {


        try {
          List<Equipment> equipmentList = equipmentService.FindAll();
            result.setData(equipmentList);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }


    }

    @ApiOperation( value = "根据kks查询设备")
    @GetMapping("/findByKks")
    public CommonResult findEquipmentByKks(@RequestParam("kks") String kks) {

        try {
            Equipment equipment = equipmentService.findEquipmentByKks(kks);
            result.setData(equipment);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }

    }


    /**
     * 通过设备的名称查找设备
     * @param equipmentName
     * @return
     */
    @ApiOperation(value = "通过设备的名称查找设备")
    @GetMapping("/findByEquipmentName")
    public CommonResult findEquipmentByEquipmentName(@RequestParam("equipmentName") String equipmentName ) {

        try {

            Equipment equipment = equipmentService.findEquipmentByEquipmentName(equipmentName);
            result.setData(equipment);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }

    }





    @ApiOperation(value = "新增设备")
    @PostMapping("/add")
    public Equipment addEquipment(@RequestBody Equipment equipment) {
        return equipmentService.addEquipment(equipment);

    }



    /**
     * 进行设备的更新
     */
    @ApiOperation(value = "更新设备")
    @PutMapping("/updateById/{id}")
    public Equipment updateById(@RequestBody Equipment equipment) {

        return equipmentService.updateById(equipment);

    }





    /**
     * 通过ID进行删除
     */

    @ApiOperation(value = "通过ID进行删除设备")
    @DeleteMapping("Equipment/{id}")
    public void deleteUser(@PathVariable("id") Long id) {

        equipmentService.deleteById(id);

    }




}
